Skip to content

fix(edit_match): prefer literal paths over glob#133

Open
tobwen wants to merge 2 commits into
cortexkit:mainfrom
tobwen:edit-match-literal-brackets
Open

fix(edit_match): prefer literal paths over glob#133
tobwen wants to merge 2 commits into
cortexkit:mainfrom
tobwen:edit-match-literal-brackets

Conversation

@tobwen

@tobwen tobwen commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #132

What and why?

Existing paths with brackets are now treated as literal files instead of glob patterns. Falls back to glob when the path doesn't exist or validation fails.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Prefer literal paths over globs in edit_match when the path exists on disk, even if it contains [ ] * ? { }. Use glob only when the path doesn’t exist.

  • Bug Fixes
    • Added should_treat_as_glob: prefer literal when validate_path resolves an existing path; on validate_path errors (including path_outside_root and unknown), defer to the single-file flow so errors surface correctly.
    • Added regression tests for bracketed literal paths (absolute and relative) and a sanity test for parentheses.

Written for commit d3d29eb. Summary will update on new commits.

Review in cubic

Greptile Summary

This PR fixes issue #132 by introducing should_treat_as_glob, which preferentially interprets a path containing glob metacharacters ([, ], *, ?, {) as a literal file path when validate_path can resolve it to an existing path on disk, falling back to glob routing only when the resolved candidate does not exist.

  • should_treat_as_glob replaces the old is_glob_pattern check at the dispatch point; it calls validate_path first and only returns true (route to glob handler) when the literal path is confirmed absent. Both path_outside_root errors and unknown validation errors defer to handle_single_file_edit_match so real errors surface properly.
  • Three new integration tests cover absolute bracketed paths, relative bracketed paths (with project-root restriction), and a parentheses sanity-check.

Confidence Score: 5/5

Safe to merge — the change is narrow and well-tested, and the previous thread's fail-safe concern has already been addressed.

The new should_treat_as_glob function correctly gates on validate_path before deciding literal-vs-glob, three integration tests exercise the key paths, and the earlier reviewer concern about unknown errors being silently promoted to glob has already been fixed in a follow-up commit.

No files require special attention.

Important Files Changed

Filename Overview
crates/aft/src/commands/edit_match.rs Adds should_treat_as_glob to prefer literal path resolution over glob matching when the file exists on disk; logic and error handling look correct.
crates/aft/tests/integration/edit_test.rs Adds three integration tests covering bracketed absolute paths, relative paths with project-root restriction, and a parentheses sanity-check; coverage is appropriate for the fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[handle_edit_match] --> B{op == append?}
    B -->|yes| C[handle_append]
    B -->|no| D[should_treat_as_glob]
    D --> E{is_glob_pattern?}
    E -->|no| F[false → single-file]
    E -->|yes| G[ctx.validate_path]
    G -->|Ok candidate| H{candidate.exists?}
    H -->|yes| I[false → single-file]
    H -->|no| J[true → glob]
    G -->|Err path_outside_root| K[false → single-file]
    G -->|Err other| L[log debug, false → single-file]
    F --> M[handle_single_file_edit_match]
    I --> M
    K --> M
    L --> M
    J --> N[handle_glob_edit_match]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[handle_edit_match] --> B{op == append?}
    B -->|yes| C[handle_append]
    B -->|no| D[should_treat_as_glob]
    D --> E{is_glob_pattern?}
    E -->|no| F[false → single-file]
    E -->|yes| G[ctx.validate_path]
    G -->|Ok candidate| H{candidate.exists?}
    H -->|yes| I[false → single-file]
    H -->|no| J[true → glob]
    G -->|Err path_outside_root| K[false → single-file]
    G -->|Err other| L[log debug, false → single-file]
    F --> M[handle_single_file_edit_match]
    I --> M
    K --> M
    L --> M
    J --> N[handle_glob_edit_match]
Loading

Reviews (4): Last reviewed commit: "fix(edit_match): fail-safe on unknown va..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

Comment thread crates/aft/src/commands/edit_match.rs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

tobwen added 2 commits June 24, 2026 05:13
Existing paths with brackets are now treated as literal files
instead of glob patterns. Falls back to glob when the path
does not exist or validation fails.
Addresses Greptile P2: the Err(_) => true catch-all silently routed
unknown validate_path errors to the glob handler. Return false instead
so the single-file handler re-validates and surfaces the error.
Dead code today (all errors use path_outside_root), zero behavior change.
@tobwen tobwen force-pushed the edit-match-literal-brackets branch from 56ca4d5 to d3d29eb Compare June 24, 2026 05:13

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(bug) AFT tools don't handle file paths that contain brackets like () []

1 participant